<template>
    <!--    <Header></Header>-->
    <div class="wrapper">
        <div class="search-head">
            <div class="ep-title"> Search</div>
            <div class="ex-header-brand-search inline">
                <div class="ex-header-brand-search-wrapper">
                    <img src="/images/search.png" alt="search">
                    <input type="text" v-model="searchText" placeholder="Please enter search terms">
                </div>
                <div class="search-btn" @click="getContent()">Search</div>
            </div>
        </div>
        <div class="search-content">
            <div class="per-content" v-for="(item, index) in tabList" :key="index">
                <div class="tab-content" :class="{ 'tab-content-active': activeIndex === item.index }"
                     @click="clickPoint(item, index)">
                    {{ item.title }} ({{ item.number }})
                </div>
            </div>
        </div>
        <!--    <div class="loading-div" v-loading="loading" v-show="loading"></div>-->
        <div class="result">
            <SearchViewArticleTab class="fade" ref="articleTab" v-show="activeIndex === 0"
                                  :update="updateData"></SearchViewArticleTab>
            <SearchViewImageTab class="img-tab fade" ref="imageTab" v-show="activeIndex === 1"
                                :update="updateData"></SearchViewImageTab>
            <SearchViewVideoTab class="fade" ref="videoTab" v-show="activeIndex === 2"
                                :update="updateData"></SearchViewVideoTab>
        </div>

    </div>
    <!--    <Footer></Footer>-->
</template>

<script setup lang="ts">

    const config = useRuntimeConfig();
    const apiURL = config.public.apiURL;
    // const hostURL = config.public.hostURL;
    const route = useRoute()
    const token = route.query.token;


    useHead({
        title: 'Exeed Newsroom',//网站标题
        link: [//网站link，可以在这里引入css和icon等
            {rel: 'shortcut icon', href: '/images/favicon.ico'},
            {rel: 'apple-touch-icon', href: '/images/favicon.ico'}
        ]
    })
    let searchText = <string>route.query.key;
    const tabUpdate = ref([false, false, false])

    // const loading = ref(true)
    const getContent = () => {

        tabUpdate.value = [false, false, false]
        // $fetch(() => {
        articleTab.value.getContent(searchText);
        imageTab.value.getContent(searchText);
        videoTab.value.getContent(searchText);
        // });
    }


    const list = ref([]);


    // const list = [1,1,1,1,1,1,1,1,1,1,1]


    const activeIndex = ref(0);

    // getContent();

    const tabList = ref([
        {
            title: `MediaInfo`,
            number: 0,
            index: 0
        },
        {
            title: `Image`,
            number: 0,
            index: 1
        },
        {
            title: `Video`,
            number: 0,
            index: 2
        }
    ]);

    const clickPoint = (item, index) => {
        activeIndex.value = item.index;
    }

    const articleTab: any = ref(null);
    const imageTab: any = ref(null);
    const videoTab: any = ref(null);

    const updateData = (type, total) => {
        if (type == "article") {
            tabList.value[0].number = total;
            tabUpdate.value[0] = true;
        }
        if (type == "image") {
            tabList.value[1].number = total;
            tabUpdate.value[1] = true;
        }
        if (type == "video") {
            tabList.value[2].number = total;
            tabUpdate.value[2] = true;
        }

    }

    // 模拟数据加载
    if (route.query.type) {
        activeIndex.value = Number(route.query.type);
    }

    if (route.query.key) {
        searchText = <string>route.query.key;
    }

    onMounted(() => {
        getContent();
    });
</script>

<style scoped lang="scss">
    .wrapper {
        background-color: #FFFFFF;
        min-height: 100%;
        width: 1920px;
        padding-top: 90px;

        .search-head {
            .ex-header-brand-search {
                // transform: translateY(-50%);
                width: 1700px;
                display: inline-flex;

                .ex-header-brand-search-wrapper {
                    width: 1360px;
                    height: 60px;
                    border: 1px solid rgba(0, 0, 0, 0.45);
                    display: flex;
                    align-items: center;
                    margin-left: 80px;
                    /* 垂直居中所有子元素 */
                    justify-content: start;


                    /* 子元素向行的起始位置对齐 */
                    img {
                        margin-left: 16px;
                        margin-right: 7px;
                        width: 24px;
                    }

                    input {
                        border: none;
                        width: 1360px;
                        /* 移除边框 */
                        outline: none;
                        /* 在选中时移除轮廓线 */
                        background-color: transparent;
                        /* 设置背景色为透明 */
                        caret-color: #000;
                        /* 字体大小 */
                        font-size: 22px;
                        color: #000;
                    }

                    input::-webkit-input-placeholder {
                        font-size: 22px;
                        line-height: 60px;
                    }
                }

                .search-btn {
                    width: 224px;
                    height: 60px;
                    background: #372E2C;
                    text-align: center;
                    font-size: 20px;
                    line-height: 60px;
                    color: #FFFFFF;
                    margin-left: 16px;
                    cursor: pointer;
                }

                .search-btn:active {
                    background: rgb(199, 142, 102, 0.58);
                }
            }


            .ep-title {
                // padding-top: 126px;
                padding-left: 80px;
                width: 369px;
                // text-align: center;
                font-size: 56px;
                color: #30363A;
                line-height: 112px;
                font-weight: 700;
            }


        }

        .search-content {
            width: 1600px;
            margin-left: 80px;
            display: inline-flex;
            border-bottom: 4px solid rgba(0, 0, 0, 0.1);

            .per-content {
                padding-top: 10px;
                user-select: none;

                .tab-content {
                    width: 150px;
                    height: 80px;
                    line-height: 80px;
                    font-size: 20px;
                    text-align: center;
                    cursor: pointer;
                }

                .tab-content-active {
                    width: 150px;
                    height: 80px;
                    line-height: 80px;
                    font-size: 20px;
                    text-align: center;
                    color: rgba(199, 142, 102, 1);
                    border-bottom: 4px solid rgba(199, 142, 102, 1);
                    cursor: pointer;
                }

            }
        }

        .fade {
            -webkit-animation-name: fade;
            -webkit-animation-duration: 1.5s;
            animation-name: fade;
            animation-duration: 1.5s;
        }

        @-webkit-keyframes fade {
            from {
                opacity: 0
            }
            to {
                opacity: 1
            }
        }
        @keyframes fade {
            from {
                opacity: 0
            }
            to {
                opacity: 1
            }
        }

    }

    .loading-div {
        width: 1680px;
        padding: 0px 100px;
        min-height: 1000px;
    }

    //修改loading加载时的颜色
    :deep(.el-loading-spinner) {
        .path {
            stroke: #372E2C;
        }
    }

</style>
